import java.util.LinkedList;
import java.util.List;

/**
 * A class hard-coded with a simple graph for testing purposes.
 */
public class TestVertex implements Vertex<TestVertex> {

	private Character letter;
	private List<Pair<TestVertex>> adjacent;

	/**
	 * Creates a vertex with a single letter as a name.
	 * 
	 * @param letter
	 *            The vertex's name
	 */
	private TestVertex(char letter) {
		if (letter < 'A' || letter > 'E') {
			throw new IllegalArgumentException();
		}

		this.letter = letter;
		adjacent = new LinkedList<Pair<TestVertex>>();
	}

	/**
	 * Builds the test graph.
	 * 
	 * @return The vertices in the graph
	 */
	public static List<TestVertex> buildTestGraph() {
		TestVertex a = new TestVertex('A');
		TestVertex b = new TestVertex('B');
		TestVertex c = new TestVertex('C');
		TestVertex d = new TestVertex('D');
		TestVertex e = new TestVertex('E');

		a.addAdjacent(b, 8);
		b.addAdjacent(a, 8);

		a.addAdjacent(c, 14);
		c.addAdjacent(a, 14);

		a.addAdjacent(d, 7);
		d.addAdjacent(a, 7);

		c.addAdjacent(d, 6);
		d.addAdjacent(c, 6);

		c.addAdjacent(e, 3);
		e.addAdjacent(c, 3);

		List<TestVertex> vertices = new LinkedList<TestVertex>();
		vertices.add(a);
		vertices.add(b);
		vertices.add(c);
		vertices.add(d);
		vertices.add(e);

		return vertices;
	}

	/**
	 * Adds a neighbor to this vertex.
	 * 
	 * @param vertex
	 *            The adjacent vertex
	 * @param weight
	 *            The edge weight
	 */
	private void addAdjacent(TestVertex vertex, int weight) {
		adjacent.add(new Pair<TestVertex>(vertex, weight));
	}

	/**
	 * Returns the list of vertices adjacent to this vertex.
	 */
	@Override
	public List<Pair<TestVertex>> getAdjacent() {
		return adjacent;
	}

	/**
	 * Determines if this vertex is equal to some other object.
	 */
	@Override
	public boolean equals(Object other) {
		return other instanceof TestVertex
				&& ((TestVertex) other).letter.equals(letter);
	}

	/**
	 * Returns the hash code of this vertex.
	 * 
	 * This method is implemented to maintain consistency with equals. See the
	 * documentation of Object.hashCode() for details.
	 */
	@Override
	public int hashCode() {
		return letter.hashCode();
	}

	/**
	 * Returns a string representation of this object.
	 */
	@Override
	public String toString() {
		return "" + letter;
	}

	/**
	 * Returns this vertex's name.
	 */
	public char getLetter() {
		return letter;
	}
}
